<script type="text/javascript">
    // Pass the checkbox name to the function
    function getCheckedBoxes(chkboxName) {
      var checkboxes = document.getElementsByName(chkboxName);
      var checkboxesChecked = [];
      // loop over them all
      for (var i=0; i<checkboxes.length; i++) {
         // And stick the checked ones onto an array...
         if (checkboxes[i].checked) {
            checkboxesChecked.push(checkboxes[i].value);
         }
      }
      // Return the array if it is non-empty, or null
      return checkboxesChecked.length > 0 ? checkboxesChecked : null;
    }

    function setTagArray() {
        var checkedBoxes = getCheckedBoxes("user[]");
        document.getElementById('tagArray').value = checkedBoxes.join(",");
        return true;
    }

</script>

<?php
include ("../main/inc/global.inc.php");

require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once (api_get_path(CONFIGURATION_PATH).'profile.conf.php');

api_block_anonymous_users(); // only users who are logged in can proceed

// Top part of the HTML
Display :: display_header('Upload');

global $_user;

?>
        <form id="uploadForm" action="UploadFile.php" method="post" enctype="multipart/form-data" onSubmit="setTagArray()">
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file"><br>
            <input id="tagArray" type="hidden" name="tagArray" value="">
            <input type="hidden" name="uploadId" value="<?php echo $_user['user_id']; ?>">
            <input type="submit" name="submitFile" value="Upload">
        </form>

        <!-- If it's not toggleable, why should someone click this button?
        <input type="button" name="tagSomeone" value="Tag Someone" onclick="document.getElementById('tagDiv').style.visibility='visible'; "/>
        -->
        <div id="tagDiv" >
		<p>Tag someone for this file (optional): </p>
        <?php
            $result = Database::getUserList();
            foreach ($result as &$row)
            {
                echo '<input type="checkbox" name="user[]" value="' . $row['user_id'] . '"/>' . $row['username'] . ' (' . $row['lastname'] . ', ' . $row['firstname'] . ')<br />';
                //echo '<P>';
            }
        ?>
	</div>
<?php
// Footer
Display :: display_footer();
?>
